﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for PictureDA
/// </summary>
public class PictureDA
{
    Connection conn = new Connection();

    public List<HinhAnh> GetData(string masanpham)
    {
        try
        {
            List<HinhAnh> lstHA = new List<HinhAnh>();
            conn.openCon();
            string sql = "SELECT * FROM HinhAnh where MaSanPham=@id";
            SqlCommand cmd = new SqlCommand(sql, conn.getCon());
            cmd.Parameters.Add("@id", System.Data.SqlDbType.VarChar).Value = masanpham;
            SqlDataReader reader = cmd.ExecuteReader();
            HinhAnh objha = null;
            while (reader.Read())
            {
               
                objha = new HinhAnh();
                objha.Id = reader.GetInt32(0);
                objha.Masanpham = reader.GetString(2);
                objha.Url = reader.GetString(1);
                lstHA.Add(objha);
            }
            reader.Close();
            conn.closeCon();
            if (lstHA.Count>1)
            {
                lstHA.RemoveAt(0);
                
            }
            return lstHA;
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.closeCon();
        }
    }
}